package org.bigjava.user.service.impl;

import org.bigjava.bean.Attention;
import org.bigjava.bean.Posts;
import org.bigjava.common.Constant;
import org.bigjava.user.mapper.PostsMapper;
import org.bigjava.user.service.PostsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PostsServiceImpl implements PostsService {
    @Autowired
    PostsMapper postsMapper;

    //实现用户创建帖子
    @Override
    public void insertPosts(Posts posts) {
        postsMapper.createPosts(posts);
    }

    //实现查看帖子详情信息
    public Posts queryPostsDetails(String postsName, int TopicId) {
        Posts posts = new Posts();
        posts.setPostTitle(postsName);
        posts.setTopicId(TopicId);
        Posts postState = postsMapper.selectPostsByName();
        if (postState.getPostState() != 0 || postState.getPostTitle() == null) {
            return null;
        } else {
            return postsMapper.selectPostsByName();
        }
    }

    //实现用户查看自己的所有帖子
    public List<Posts> queryAllMyPosts(long userid) {
        List<Posts> posts = postsMapper.queryAllMyPosts(userid);
        return posts;
    }

    //实现用户删除帖子
    @Override
    public void deletePosts(int postsId, int topicId) {
        Map<String, Object> map = new HashMap<>();
        map.put("postsId", postsId);
        map.put("topicId", topicId);
        postsMapper.deletePosts(map);
    }


    //实现用户查询帖子
    @Override
    public List<Posts> inquirePosts(String postsName) {

        return null;
    }


    //实现首页用户个性动态推荐
    @Override
    public List<Attention> personalityPosts(long userid) {
        List<Attention> personalityPosts = postsMapper.personalityPosts(userid);
        return personalityPosts;
    }

    //实现帖子热度排行
    public List<Posts> postsHot() {
        return postsMapper.PostsHot();
    }


}
